#pragma once

#include <functional>
#include <map>
#include <memory>
#include <mutex>
#include <utility>
#include <list>

#include "ui_element.h"

using GameElementPtr = std::shared_ptr<UIElement>;

class Game {
public:
    // init
    int ReadMap();

    // loop
    void VisitAllElement(std::function<void(const GameElementPtr e)> fn, bool update);

    // event
    void OnKey(int32_t key, int32_t action, int32_t mods);
    void OnMouseButton(int button, int action, int mods);
    void OnMousePosition(int x, int y);

private:
    void Update();
    bool CheckBullet(const GameElementPtr &bullet);

    long long lasttime;

public:
    std::mutex elementsMutex;
    std::list<GameElementPtr> elements; // [e, e, ...]
};
